package org.example.design.flyweight.test1;

import java.util.HashMap;

/**
 * @author huangshen
 * @version 0
 * @description 生成和公用BigChar的类
 * @since 2022/2/11 14:37
 */
public class BigCharFactory {

    private final HashMap<String, BigChar> pool = new HashMap<>();

    private static final BigCharFactory SINGLETON = new BigCharFactory();

    private BigCharFactory() {}

    public static BigCharFactory getInstance() {
        return SINGLETON;
    }

    public synchronized BigChar getBigChar(char charName) {
        BigChar bc = pool.get(String.valueOf(charName));
        if(bc == null) {
            bc = new BigChar(charName);
            pool.put(String.valueOf(charName), bc);
        }
        return bc;
    }
}
